<style scoped>
    * {
        box-sizing: border-box;
        -webkit-tap-highlight-color: transparent;
    }
    * {
        word-wrap: break-word;
    }
    table {
        width: 100%;
        empty-cells: show;
        background-color: transparent;
        border-collapse: collapse;
        border-spacing: 0;
    }
    .text-c {
        text-align: center;
    }
    .table-bg thead th {
        background-color: #f5fafe;
        border-right: 0px solid #e9eaec;
    }
    .table th, .table td {
        padding: 8px;
        line-height: 20px;
        word-break: break-all;
        border-right: 0px solid #e9eaec;
    }

    .table th {
        font-weight: bold;
    }
    .noModal{
        position:inherit;
        background-color: white;
    }
    .noModal .form-modal{
        position:inherit
    }
</style>
<template>
    <transition name="fade">
        <div :class="['form-modal-wrap',{'noModal':!IsModal}]" v-show='modalShowVisible'>
            <transition name="slideUp">
                <div style="width:96%;top: 50px;text-align:center" class="form-modal"  v-show='modalShowVisible'>
                    <img class='modal-close' src='../../assets/images/icon_close.png' @click.stop='closeModal()' v-show="IsModal">
                    <div class="modal-header">
                        <Select v-model="searchData.searchId" style="width:200px" placeholder="选择规则类型" @on-change="changeTitle()" v-if="all.length>0">
                            <Option :value=row.id v-for="row in all" :key=row.id>{{row.title}}</Option>
                        </Select>
                        <h4>{{Title}}</h4>
                    </div>
                    <div class="modal-body">
                        <Card :bordered="false" v-for="(clist,index) in list" :key="'list_'+index">
                            <p slot="title">规则{{index+1}}</p>
                            <a href="#" slot="extra" @click.prevent="handleRemoveCard(index)" style="font-size: 24px;color: red;" title="删除规则">
                                <Icon type="ios-trash" />
                            </a>
                            <table class="table table-bg table-hover table-sort">
                                <thead>
                                <tr class="text-c">
                                    <th style="text-align: center;width: 15%;">选项名称</th>
                                    <th style="text-align: center;width: 10%;">op操作</th>
                                    <th style="text-align: center;">值</th>
                                    <th style="text-align: center;width: 20%;">提示</th>
                                    <th style="text-align: center;width: 15%;">操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <tr class="text-c" v-for="(item,itx) in clist" :key="'item_'+itx">
                                    <td>
                                        <Select v-model="item.field" @on-change="selectFiled(clist,index,itx)" transfer>
                                            <Option :value="row.key" v-for="row in fields" :key="row.key" >{{row.name}}</Option>
                                        </Select>
                                    </td>
                                    <td>
                                        <Select v-model="item.op" @on-change="selectOP(clist,itx)" transfer>
                                            <Option :value="row.key" v-for="row in getOps(item.field)" :key="row.key">{{row.name}}</Option>
                                        </Select>
                                    </td>
                                    <td>
                                        <template v-if="checkIsArrayForOp(item.field,item.op)">
                                            <Select v-model="item.valueArr" clearable filterable transfer :multiple="IsMultipleOp(item.op)" v-if="item.field !='imsi'&& item.field!='city' && item.field !='provider' && item.field !='region2' && item.field !='region3'" :ref="index+'item_'+itx">
                                                <Option :value="row.id"  :label="row.name" v-for="row in filedArrValue[item.field]" :key="row.id" >{{row.name}}</Option>
                                            </Select>
                                            <Select  v-model="item.valueArr" clearable  transfer  filterable :multiple="IsMultipleOp(item.op)" v-else style="text-align: left;" :ref="index+'item_'+itx">
                                                <OptionGroup :value="row1.id"  :label="row1.name" v-for="row1 in filedArrValue[item.field]" :key="'group_'+row1.id"  >
                                                    <Option :value="row.id" :label="row.name"   v-for="row in row1.list" :key="row.id">({{row.id}}){{row.name}}</Option>
                                                </OptionGroup>
                                            </Select>
                                        </template>
                                        <template v-else>

                                            <Input type="text" v-model.trim="item.value" :placeholder="getPlaceholder(item.field)" v-show="item.op!='in'&&item.op!='ni'"></Input>
                                            <Input type=textarea :autosize="{minRows: 2,maxRows: 3}" :rows='2' v-model.trim=item.value placeholder="请输入值,如多个值请用','隔开" v-show="item.op=='in'||item.op=='ni'"></Input>
                                        </template>
                                    </td>
                                    <td><label style="color:blue">{{!IsMultipleOp(item.op)?"不支持多个值":"支持多个值(用“,”隔开)"}}
                                    <br><span style="color:red">{{getItemType(item.field)}}</span></label></td>
                                    <td width="150px"><Button type="error" @click="handleRemove(clist,itx)" class="ml-10">删除</Button></td>
                                </tr>
                                <tr>
                                    <td colspan="1"></td>
                                    <td colspan="2"><Button type="dashed" long @click="handleAdd(clist)" icon="plus-round">新增</Button></td>
                                </tr>
                                </tbody>
                            </table>
                        </Card>
                        <Button type="warning" long @click="handleAddCard()" icon="plus-round" style="margin: 20px 0;width: 80%;">新增规则</Button>
                        <Button type="success" long @click="handleSaveData()" icon="ios-cloud-upload" style="margin: 0 0 20px 0;width: 80%;">保存</Button>
                    </div>
                </div>
            </transition>
        </div>
    </transition>
</template>
<script>
    import Vue from "vue";
    import {Switch,Card} from "view-design"
    import EventBus from "../../commons/EventBus";
    import tipModal from "../tipModal/";
    import utils from '../../commons/utils';
    import store from "@/commons/store"
    const { platform,PF} = require("../../../package.json")
    import Imsi from "@/commons/Imsi";
    export default {
        name: "ruleView",
        components:{ISwitch:Switch,Card},
        props:{
            Filter:{
                type:String,
                default:"",
            },
            Title:String,
            IsModal:{
                type:Boolean,
                default:true,
            },
            all:{
                type:Array,
                default:()=>{return []}
            },
            id:Number
        },
        computed:{
            modalShowVisible(){
                return !this.IsModal||this.modalVisible;
            },
        },
        watch:{
            Filter(){
                this.initList();
            }
        },
        data(){
            return {
                searchData:{
                    searchId:1,
                    searchOldId:1,
                },
                list:[],
                modalVisible:false,
                fieldTypeObj:{},
                fieldList:[],
                opsList:[],
                SpecialStringOps :["ct","nct","sw","nsw","ew","new"],
                SpecialStringOps1 :["ct","nct"],
                MultipleOp:["in","ni","insw","nisw"],
                fieldsCn:[
                    {"key":"city","name":"城市ID","type":"int"},
                    {"key":"province","name":"省ID","type":"int"},
                ],
                fieldsGw:[
                    {"key":"region3","name":"国家ID","type":"int","ops":["eq","ne","gt","ge","lt","le","in","ni"]},
                    {"key":"region2","name":"地区ID","type":"int","ops":["eq","ne","gt","ge","lt","le","in","ni"]},
                    {"key":"region1","name":"大洲ID","type":"int","ops":["eq","ne","gt","ge","lt","le","in","ni"]},
                ],
                fields:[
                    {"key":"sdkversion","name":"SDK版本号","type":"int","ops":["eq","ne","gt","ge","lt","le","in","ni"]},
                    {"key":"channel","name":"渠道号","type":"string","ops":["all"]},
                    {"key":"usercreated","name":"用户注册时间","type":"string","ops":["all"]},
                    {"key":"uuid","name":"设备UUID","type":"string","ops":["all"]},
                    {"key":"imei","name":"IMEI","type":"string","ops":["all"]},
                    {"key":"imsi","name":"IMSI","type":"string","ops":["all"]},
                    {"key":"vendor","name":"手机品牌","type":"string","ops":["all"]},
                    {"key":"model","name":"手机型号","type":"string","ops":["all"]},
                    {"key":"versionname","name":"系统版本描述","type":"string","ops":["all"]},
                    {"key":"versioncode","name":"系统版本号","type":"int","ops":["eq","ne","gt","ge","lt","le","in","ni"]},
                    {"key":"sdcardFreeSize","name":"SD卡剩余空间","type":"int","ops":["eq","ne","gt","ge","lt","le","in","ni"]},
                    {"key":"apppackage","name":"主体应用包名","type":"string","ops":["all"]},
                    {"key":"existpackages","name":"手机已存在的应用","type":"string","ops":["ct","nct","sw","nsw","ew","new"]},
                    {"key":"screenstate","name":"屏幕亮屏状态","type":"int","ops":["all"]},
                    {"key":"androidid","name":"androidId","type":"string","ops":["all"]},
                    {"key":"serialno","name":"设备序列号","type":"string","ops":["all"]},
                    {"key":"screenwidth","name":"屏幕宽度","type":"int","ops":["eq","ne","gt","ge","lt","le","in","ni"]},
                    {"key":"screenheight","name":"屏幕高度","type":"int","ops":["eq","ne","gt","ge","lt","le","in","ni"]},
                    {"key":"screendensity","name":"屏幕密度","type":"int","ops":["eq","ne","gt","ge","lt","le","in","ni"]},
                    {"key":"mac","name":"mac地址","type":"string","ops":["all"]},
                    {"key":"net","name":"网络类型","type":"int","ops":["eq","ne","gt","ge","lt","le","in","ni"]},
                    {"key":"ip","name":"IP","type":"string","ops":["all"]},
                    {"key":"hour","name":"时","type":"int","ops":["eq","ne","gt","ge","lt","le","in","ni"]},
                    {"key":"week","name":"周","type":"int","ops":["eq","ne","gt","ge","lt","le","in","ni"]},
                    {"key":"random","name":"随机数","type":"int","ops":["eq","ne","gt","ge","lt","le","in","ni"]},
                    // {"key":"isyunos","name":"是否yunos系统","type":"int","ops":["eq","ne","gt","ge","lt","le","in","ni"]},
                    {"key":"minute","name":"分钟数","type":"int","ops":["eq","ne","gt","ge","lt","le"]},
                    {"key":"usercreatedsec","name":"用户注册时长(秒)","type":"int","ops":["eq","ne","gt","ge","lt","le"]},
                    {"key":"existpkgnames","name":"手机已存在的应用","type":"string","tip":"eg:a.b.c","ops":["ct","nct"]},
                    {"key":"existpkgnamevers","name":"手机已存在的应用#版本号","type":"string","tip":"eg:a.b.c#200","ops":["ct","nct"]},
                ],
                ops:[
                    {"key":"eq","name":"等于"},
                    {"key":"ne","name":"不等于"},
                    {"key":"gt","name":"大于"},
                    {"key":"ge","name":"大于等于"},
                    {"key":"lt","name":"小于"},
                    {"key":"le","name":"小于等于"},
                    {"key":"in","name":"在数组内"},
                    {"key":"ni","name":"不在数组内"},
                    {"key":"ct","name":"字符串包含xx"},
                    {"key":"nct","name":"字符串不包含xx"},
                    {"key":"sw","name":"字符串以XX起始"},
                    {"key":"nsw","name":"字符串不以XX起始"},
                    {"key":"ew","name":"字符串以XX结束"},
                    {"key":"new","name":"字符串不以XX结束"},
                    {"key":"insw","name":"字符串以XX开始(数组)"},
                    {"key":"nisw","name":"字符串不以XX开始(数组)"},
                ],
                filedArrValue:{
                    "net":[{"id":1,"name":"wifi"},{"id":2,"name":"2G"},{"id":3,"name":"3G"},{"id":4,"name":"4G"},{"id":9,"name":"其它"}],
                    "week":[{"id":0,"name":"周日"},{"id":1,"name":"周一"},{"id":2,"name":"周二"},{"id":3,"name":"周三"},{"id":4,"name":"周四"},{"id":5,"name":"周五"},{"id":6,"name":"周六"}],
                    "hour":[{"id":0,"name":"00"},{"id":1,"name":"01"},{"id":2,"name":"02"},{"id":3,"name":"03"},{"id":4,"name":"04"},{"id":5,"name":"05"},{"id":6,"name":"06"},{"id":7,"name":"07"},{"id":8,"name":"08"},{"id":9,"name":"09"},{"id":10,"name":"10"},{"id":11,"name":"11"},{"id":12,"name":"12"},{"id":13,"name":"13"},{"id":14,"name":"14"},{"id":15,"name":"15"},{"id":16,"name":"16"},{"id":17,"name":"17"},{"id":18,"name":"18"},{"id":19,"name":"19"},{"id":20,"name":"20"},{"id":21,"name":"21"},{"id":22,"name":"22"},{"id":23,"name":"23"}],
                    // "isyunos":[{"id":1,"name":"是"},{"id":0,"name":"否"}],
                    "versioncode":[{"id":1,"name":'1.0'},{"id":2,"name":'1.1'},{"id":3,"name":'1.5'},{"id":4,"name":'1.6'},{"id":5,"name":'2.0'},{"id":6,"name":'2.0.1'},{"id":7,"name":'2.1'},{"id":8,"name":'2.2.x'},{"id":9,"name":'2.3-2.3.2'},{"id":10,"name":'2.3.3-2.3.7'},{"id":11,"name":'3.0'},{"id":12,"name":'3.1'},{"id":13,"name":'3.2.x'},{"id":14,"name":'4.0.1-4.0.2'},{"id":15,"name":'4.0.3-4.0.4'},{"id":16,"name":'4.1.x'},{"id":17,"name":'4.2.x'},{"id":18,"name":'4.3.x'},{"id":19,"name":'4.4-4.4.4'},{"id":20,"name":'4.4W'},{"id":21,"name":'5.0'},{"id":22,"name":'5.1'},{"id":23,"name":'6.0'},{"id":24,"name":'7.0'},{"id":25,"name":'7.1-7.1.1'},{"id":26,"name":'8.0'},{"id":27,"name":'8.1'},{"id":28,"name":'9'},{"id":29,"name":'10'},{ "id": 30, "name": "11" }],
                    "screenstate":[{"id":1,"name":'亮屏'},{"id":2,"name":'暗屏'}],
                    "provider":[
                        {"id":"1","name":'移动',"list":[{"id":"46000","name":"46000"},{"id":"46002","name":"46002"},{"id":"46007","name":"46007"}]},
                        {"id":'2',"name":'联通',list:[{"id":"46001","name":"46001"},{"id":"46006","name":"46006"}]},
                        {"id":"3","name":'电信',list:[{"id":"46003","name":"46003"},{"id":"46005","name":"46005"}]},
                        {"id":"4","name":"铁通",list:[{"id":"46020","name":"46020"}]}]
                },
            }
        },
        methods:{

            async changeTitle(){
                if(this.searchData.searchOldId !=this.searchData.searchId){
                    // console.log("Old New",this.searchData.searchOldId,this.searchData.searchId)
                    let t =  await this.changeData();
                    this.searchData.searchOldId = this.searchData.searchId;
                    if(t){
                        this.initList();
                    }
                }else{
                    this.initList();
                }
            },
            initList(){
                this.fieldTypeObj = {};
                this.fields.forEach(item=>{
                    this.fieldTypeObj[item.key] = item.type;
                })
                this.list = [];

                let data = this.Filter;
                console.log(data)
                for(let i=0;i<this.all.length;i++){
                    if(this.all[i].id==this.searchData.searchId){
                        data = this.all[i].data;
                        break;
                    }
                }
                if(data !== ""){
                    this.list = JSON.parse(data)
                    this.list.forEach(cList=>{
                        cList.forEach(item=>{
                            if(!this.checkIsArrayForOp(item.field,item.op)){
                                if(item.field == "city" || item.field == "province"){
                                    let _value = item.value;
                                    if(this.IsMultipleOp(item.op)){
                                        let _valueArr = [];
                                        _value.forEach(_v=>{
                                            _valueArr.push(parseInt(_v));
                                        })
                                        item.valueArr = _valueArr
                                    }else{
                                        item.valueArr = parseInt(item.value)
                                    }
                                }
                                else if(item.field == "usercreated"){
                                    // console.log(item.field)
                                    let _value = item.value;
                                    if(this.IsMultipleOp(item.op)){
                                        let _valueArr = [];
                                        _value.forEach(_v=>{
                                            _valueArr.push(utils.dateFormat(_v,"yyyy-MM-dd HH:mm:ss"));
                                        })
                                        item.value = _valueArr
                                    }else{
                                        item.value = utils.dateFormat(item.value,"yyyy-MM-dd HH:mm:ss")
                                    }
                                }else if(item.field == "region1" || item.field == "region2" || item.field == "region3"){
                                    let _value = item.value;
                                    if(this.IsMultipleOp(item.op)){
                                        let _valueArr = [];
                                        _value.forEach(_v=>{
                                            _valueArr.push(parseInt(_v));
                                        })
                                        item.valueArr = _valueArr
                                    }else{
                                        item.valueArr = parseInt(item.value)
                                    }
                                }
                                else{
                                    if(this.IsMultipleOp(item.op)){
                                        item.value = item.value.join(",")
                                    }
                                }
                            }else{
                                item.valueArr = item.value
                                item.value = "";
                            }
                        })
                    })
                }
                if(platform.includes("cn")) {
                    this.filedArrValue["province"] = utils.cloneObj(store.getters.ProvinceList);
                    this.filedArrValue["city"] = utils.cloneObj(store.getters.CitysList);
                }else{
                    this.filedArrValue["region1"] = utils.cloneObj(store.getters.Region1List);
                    this.filedArrValue["region2"] = utils.cloneObj(store.getters.Region2List);
                    this.filedArrValue["region3"] = utils.cloneObj(store.getters.Region3List);
                }
                this.filedArrValue["imsi"] = utils.cloneObj(Imsi.List);
                // console.log(store.getters.ProvinceList)
            },
            checkData(){
                let data = [];
                let errorIndex = 0;
                let errorfield="";
                let errorMsg ="";
                let returnObj = {"data":"","errMsg":""};
                for(let i = 0;i<this.list.length;i++){
                    errorIndex = i;
                    let ruleData = [];
                    for(let j=0;j<this.list[i].length;j++) {
                        let info = JSON.parse(JSON.stringify(this.list[i][j]));
                        let field = info.field;
                        let op = info.op;
                        let type = this.fieldTypeObj[field];
                        if (this.fieldList.indexOf(field) < 0) {
                            errorfield = field;
                            errorMsg = "选项不在范围内";
                            returnObj.errMsg = "规则" + (errorIndex + 1) + "《" + this.getfieldName(errorfield) + "》" + errorMsg;
                            return returnObj;
                            break;
                        }
                        if (this.opsList.indexOf(op) < 0) {
                            errorfield = op;
                            errorMsg = "op操作不在范围内";
                            returnObj.errMsg = "规则" + (errorIndex + 1) + "《" + this.getfieldName(errorfield) + "》" + errorMsg;
                            return returnObj;
                        }
                        if (field == "usercreated") {
                            let _time = utils.checkDateTime(info.value);
                            if (_time == 0) {
                                errorfield = field;
                                errorMsg = "时间格式错误，格式为:yyyy-mm-dd h:i:s";
                                returnObj.errMsg = "规则" + (errorIndex + 1) + "《" + this.getfieldName(errorfield) + "》" + errorMsg;
                                return returnObj;
                            } else {
                                info.value = _time;
                            }
                        }
                        if(field == "existpackages"){
                            if(this.SpecialStringOps.indexOf(op)<0){
                                errorfield = field;
                                errorMsg = "操作符只能是字符串包含xx/字符串不包含xx/字符串以XX起始/字符串不以XX起始/字符串以XX结束/字符串不以XX结束";
                                returnObj.errMsg = "规则" + (errorIndex + 1) + "《" + this.getfieldName(errorfield) + "》" + errorMsg;
                                return returnObj;
                            }
                            if(info.value == ""){
                                errorfield = field;
                                errorMsg = "值不能为空";
                                returnObj.errMsg = "规则" + (errorIndex + 1) + "《" + this.getfieldName(errorfield) + "》" + errorMsg;
                                return returnObj;
                            }
                        }
                        if(field == "existpkgnames" || field == "existpkgnamevers"){
                            if(this.SpecialStringOps1.indexOf(op)<0){
                                errorfield = field;
                                errorMsg = "操作符只能是字符串包含xx/字符串不包含xx";
                                returnObj.errMsg = "规则" + (errorIndex + 1) + "《" + this.getfieldName(errorfield) + "》" + errorMsg;
                                return returnObj;
                            }
                            if(info.value == ""){
                                errorfield = field;
                                errorMsg = "值不能为空";
                                returnObj.errMsg = "规则" + (errorIndex + 1) + "《" + this.getfieldName(errorfield) + "》" + errorMsg;
                                return returnObj;
                            }
                        }
                        if (this.checkIsArrayForOp(field,op)) {
                            info.value = info.valueArr;
                        }
                        if (this.IsMultipleOp(op)) {
                            if (this.checkIsArrayForOp(field,op)) {
                                if (info.value.length == 0) {
                                    errorfield = field;
                                    errorMsg = "数组为空";
                                    returnObj.errMsg = "规则" + (errorIndex + 1) + "《" + this.getfieldName(errorfield) + "》" + errorMsg;
                                    return returnObj;
                                }
                            } else {
                                if (info.value.indexOf("，") > -1) {
                                    errorfield = field;
                                    errorMsg = "包含了中文逗号";
                                    returnObj.errMsg = "规则" + (errorIndex + 1) + "《" + this.getfieldName(errorfield) + "》" + errorMsg;
                                    return returnObj;
                                } else {
                                    let value = info.value.split(",")
                                    info.value = [];
                                    for (let k = 0; k < value.length; k++) {
                                        let val = value[k];
                                        if (type == "int") {
                                            //val = parseInt(value[k]);
                                            if (isNaN(parseInt(val))) {
                                                errorfield = info.field;
                                                errorMsg = "不是数字,请重新输入";
                                                returnObj.errMsg = "规则" + (errorIndex + 1) + "《" + this.getfieldName(errorfield) + "》" + errorMsg;
                                                return returnObj;
                                            }
                                            info.value.push(parseInt(val));
                                        }else{
                                            info.value.push(val);
                                        }
                                    }
                                }
                            }
                        } else {
                            // console.log(type)
                            if (type == "int" || op == "gt" || op == "ge" || op == "lt" || op == "le") {
                                // console.log(info.field,info.value)
                                if(info.field == "week" || info.field == "hour"){
                                    if (info.value === "" || typeof (info.value) == "undefined") {
                                        errorfield = info.field;
                                        errorMsg = "请填写或者选择一个值";
                                        returnObj.errMsg = "规则" + (errorIndex + 1) + "《" + this.getfieldName(errorfield) + "》" + errorMsg;
                                        return returnObj;
                                    }
                                }else{
                                    // console.log(info.field,info.value)
                                    if (info.value == "" || typeof (info.value) == "undefined") {
                                        errorfield = info.field;
                                        errorMsg = "请填写或者选择一个值";
                                        returnObj.errMsg = "规则" + (errorIndex + 1) + "《" + this.getfieldName(errorfield) + "》" + errorMsg;
                                        return returnObj;
                                    }
                                }
                                info.value = parseInt(info.value);
                                if (isNaN(info.value)) {
                                    errorfield = info.field;
                                    errorMsg = "不是数字,请重新输入";
                                    returnObj.errMsg = "规则" + (errorIndex + 1) + "《" + this.getfieldName(errorfield) + "》" + errorMsg;
                                    return returnObj;
                                }
                            }
                        }
                        ruleData.push({"field":info.field,"op":info.op,"value":info.value})
                    }
                    data.push(ruleData);
                }
                returnObj.data = JSON.stringify(data);
                return returnObj;
            },
            getPlaceholder(key){
                // console.log(key)
                let cnt = this.fields.length;
                for(let i = 0;i<cnt;i++){
                    if(this.fields[i].key == key){
                        if(this.fields[i].tip){
                            return "请输入"+this.fields[i].name+","+this.fields[i].tip;
                        }else{
                            return "请输入"+this.fields[i].name;
                        }
                        break;
                    }
                }
                return "请输入值";
            },
            getOps(key){
                let ops = [];
                for(let i=0;i<this.fields.length;i++){
                    if(this.fields[i].key==key){
                        if(this.fields[i].ops.length>0){
                            if(this.fields[i].ops[0]=="all"){
                                ops = this.ops;
                            }else{
                                this.ops.forEach(op=>{
                                    if(this.fields[i].ops.indexOf(op.key)>-1){
                                        ops.push(op);
                                    }
                                })
                            }
                        }
                        break;
                    }
                }
                return ops;
            },
            // getOps(key){
            //     if(key == "existpkgnames" || key == "existpkgnamevers"){
            //         return [ {"key":"ct","name":"包含xx"},{"key":"nct","name":"不包含xx"}];
            //     }else if(key == "apppackage"){
            //         return [
            //             {"key":"eq","name":"等于"},
            //             {"key":"ne","name":"不等于"},
            //             {"key":"in","name":"在数组内"},
            //             {"key":"ni","name":"不在数组内"},
            //             {"key":"ct","name":"包含xx"},
            //             {"key":"nct","name":"不包含xx"},
            //             {"key":"sw","name":"以XX起始"},
            //             {"key":"nsw","name":"不以XX起始"},
            //             {"key":"ew","name":"以XX结束"},
            //             {"key":"new","name":"不以XX结束"}
            //         ];
            //     }
            //     return this.ops;
            // },
            async handleSaveData(){
                if(this.all.length == 0){
                    let data = this.checkData();
                    if(data.errMsg!=""){
                        tipModal.open(data.errMsg);
                        return;
                    }
                    if (typeof(data.data) == "undefined"){
                        return;
                    }else{
                        if(data.data==this.data){
                            tipModal.open("数据未有任何变动");
                            return;
                        }
                        this.$emit("onSave",{"id":this.id,"data":data.data})
                    }
                }
                else{
                    if(this.searchData.searchOldId == this.searchData.searchId){
                        if(!await this.changeData()){
                            return;
                        }
                    }
                    // let ruledata = '[[{"field":"apppackage","op":"eq","value":"4456"}],[{"field":"imei","op":"eq","value":"4"}]]';
                    // console.log("all+",this.all)
                    let dataList = {}
                    this.all.forEach(item=>{
                        dataList[item.id] = item.data;
                    })
                    this.$emit("onSave",{"id":this.id,"data":dataList})

                    // let dataList = {}
                    // this.all.forEach(item=>{
                    //     dataList[item.id] = item.data;
                    // })
                    // this.$emit("onSave",{"id":this.id,"data":dataList})
                }
            },
            async changeData(){
                let data = this.checkData();
                if(data.errMsg != ""){
                    tipModal.open(data.errMsg);
                    return false;
                }
                if(data.data == "" || typeof(data.data) == "undefined"){
                    return false;
                }
                // console.log(this.all);
                let cnt = this.all.length;
                for(let i = 0;i<cnt;i++){
                    if(this.all[i].id == this.searchData.searchOldId){
                        let orgData = this.all[i];
                        orgData.data = data.data;
                        this.all.splice(i,1,orgData)
                        break;
                    }
                }
                return true;

            },
            handleRemove(clist,index){
                clist.splice(index,1)
            },
            handleAdd(clist){
                clist.push({"field":"","op":"","value":"","valueArr":[]});
            },
            handleAddCard(){
                this.list.push([])
            },
            handleRemoveCard(index){
                this.list.splice(index,1)
            },
            closeModal(){
                this.modalVisible = false;
                this.$emit("onClose",this._uid)
            },
            getfieldName(field){
                let fieldName = "";
                for(let i=0;i<this.fields.length;i++){
                    if(this.fields[i].key == field){
                        fieldName  = this.fields[i].name;
                        break;
                    }
                }
                return fieldName;
            },
            getItemType(field){
                if(this.checkIsArray(field)){
                    return "请选择列表选项";
                }else{
                    let fieldType=this.fieldTypeObj[field]
                    if(fieldType!=undefined){
                        if(fieldType == "string"){
                            return "(仅填字符串)"
                        }else{
                            return "(仅填数字)"
                        }
                    }
                }
                return "";
            },
            checkIsArray(field){
                return this.filedArrValue.hasOwnProperty(field);
            },
            checkIsArrayForOp(field,op){
                if(field=="imsi"){
                    if(op=="insw"||op=="nisw"){
                        return true;
                    }else{
                        return false;
                    }
                }else{
                    return this.checkIsArray(field);
                }
            },
            selectFiled(clist,index,itx){
                clist[itx].value = "";
                clist[itx].valueArr = "";
                if(this.$refs[index+'item_'+itx]){
                    this.$refs[index+'item_'+itx][0].clearSingleSelect()
                } 
            },
            selectOP(clist,index){
                clist[index].value = "";
                clist[index].valueArr = "";
                if(clist[index].field == "existpackages"){
                    if(this.SpecialStringOps.indexOf(clist[index].op)<0){
                        clist[index].op = "";
                        utils.showTip("操作符只能是字符串包含xx/字符串不包含xx/字符串以XX起始/字符串不以XX起始/字符串以XX结束/字符串不以XX结束")
                    }
                }
            },
            IsMultipleOp(key){
                return this.MultipleOp.indexOf(key)>-1;
            }
        },
        async mounted(){
             await Imsi.init();
            if(platform.includes("cn")) {
                this.fields = this.fields.concat(this.fieldsCn);
            }else{
                this.fields = this.fields.concat(this.fieldsGw);
            }
            this.fields.forEach(item=>{
                this.fieldList.push(item.key);
            });
            this.ops.forEach(item=>{
                this.opsList.push(item.key)
            });
            this.initList();
        },
    }
</script>